package com.owc.controller.admin;

import com.owc.common.custom.annotation.Advice;
import com.owc.common.custom.annotation.permission.PassRequest;
import com.owc.domain.BaseResult;
import com.owc.domain.dto.admin.WithdrawDetailDTO;
import com.owc.domain.dto.admin.WithdrawListDTO;
import com.owc.domain.vo.admin.BatchReviewVo;
import com.owc.domain.vo.admin.CallbackRequest;
import com.owc.domain.vo.admin.ConfirmRequest;
import com.owc.domain.vo.admin.WithdrawVo;
import com.owc.service.admin.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author xiaom
 * @Date 2019/12/12 17:02
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/admin/finance")
public class FinanceController {

    @Autowired
    private FinanceService financeService;

    /**
     * 获取审核列表
     */
    @PostMapping(value = "/list")
    public BaseResult<List<WithdrawListDTO>> withdrawList(@RequestBody @Valid WithdrawVo withdrawVo){
        return financeService.getWithdrawList(withdrawVo);
    }

    @PostMapping(value = "/batchReview")
    public BaseResult<Boolean> batchReview(@RequestBody @Valid BatchReviewVo batchReviewVo) throws Exception {
        return BaseResult.success(financeService.batchReview(batchReviewVo));
    }

    /**
     * 获取提现订单详情
     */
    @PostMapping(value = "/transferDetail")
    public BaseResult<WithdrawDetailDTO> transferDetail(@RequestBody WithdrawVo withdrawVo){
        Assert.notNull(withdrawVo.getTransferId(),"转账ID不能为空");
        return BaseResult.success(financeService.getTransferDetail(withdrawVo.getTransferId()));
    }

    @PostMapping(value = "/retryReview")
    public BaseResult<Boolean> retryReview(@RequestBody WithdrawVo withdrawVo){
        Assert.notNull(withdrawVo.getTransferId(),"转账ID不能为空");
        return BaseResult.success(financeService.retryReview(withdrawVo.getTransferId()));
    }

    /**
     * 钱包服务回调接口
     */
    @PostMapping(value = "/callbackWallet")
    @ResponseBody
    public BaseResult<Boolean> callbackWallet(@RequestBody @Advice(need = false) CallbackRequest callbackRequest) throws Exception {
        return financeService.callbackWallet(callbackRequest);
    }

    /**
     * 取消交易
     * @param txHash 交易hash
     */
    @GetMapping(value = "/cancelOrder")
    public BaseResult<Boolean> cancelOrder(@Valid @NotNull(message = "txHash不能为空") String txHash) throws Exception {
        return financeService.cancelOrder(txHash);
    }

}
